﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LeanEngine.Data.Linq.Language
{
    public sealed class OrderbyToken : IQueryToken
    {
        #region Constructor Members

        public OrderbyToken()
        {
            this.ColumnList = new List<OrderedColumnToken>();
        }

        #endregion

        #region PropertyInfo Members

        internal List<OrderedColumnToken> ColumnList { get; set; }

        #endregion

        #region ILanguageToken Members

        public string GetStatement()
        {
            var sql = "ORDER BY ";
            foreach (var orderedColumn in this.ColumnList)
            {
                sql += orderedColumn.GetStatement();
                if (this.ColumnList.Last() != orderedColumn)
                {
                    sql += ", ";
                }
            }

            return sql;
        }

        #endregion
    }
}
